#!/bin/bash

if [ ${BE_UI_VERSION}="" ] ;then
    BE_UI_VERSION=${CI_COMMIT_REF_NAME}
fi

rm -rf publish
mkdir publish
cp publish.json publish/package.json
cp publish.md publish/README.md
cp -r build publish/
sed -i s/{version}/${BE_UI_VERSION}/ publish/package.json
sed -i s/{version}/${BE_UI_VERSION}/ publish/README.md
token=//npm.prod.intra.knownsec.com/:_authToken="${BE_NPM_TOKEN}"
echo ${token} >> ~/.npmrc

npm unpublish zoomeyebe-ui@${BE_UI_VERSION} --force --registry https://npm.prod.intra.knownsec.com  --strict-ssl false
pushd publish
npm publish --strict-ssl false
popd

echo "publish ${BE_UI_VERSION} finished"